{
  LW ModTool -- Modeler Interactive Tools

  Layout tool plug-ins are just custom Layout tools.
  To the user, they behave like Layout's built-in tools
  (the tools activated by the Move, Rotate and Scale buttons, for example).

  Based on lwlaytool.h which is:
  Copyright 2001, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}

unit LW_ModTool;

{$mode objfpc}{$H+}

interface

uses
  LW_Types   ,
  LW_Tool    ,
  LW_Meshedt ;

const
  LWMESHEDITTOOL_CLASS    = 'MeshEditTool' ;
  LWMESHEDITTOOL_VERSION  = 4 ;

  { The test function can return code for the next action to be performed
    to modify the edit state.

    NOTHING  do nothing.  The edit state remains unchanged.

    UPDATE   reapply the operation with new settings.  The 'build' func
         is called.

    ACCEPT   keep the last operation.  The 'end' callback is called with
         the 'keep' argument true.

    REJECT   discard the last operation.  The 'end' callback is called
         with the 'keep' argument false.

    CLONE    keep the last operation and begin a new one.  'End' is
         called with a true 'keep' parameter, and then 'build' is
         called again.                                                      }

   LWT_TEST_NOTHING  = 0 ;
   LWT_TEST_UPDATE   = 1 ;
   LWT_TEST_ACCEPT   = 2 ;
   LWT_TEST_REJECT   = 3 ;
   LWT_TEST_CLONE    = 4 ;

type
  { The MeshEdit tool is a LightWave viewport tool that performs its
    action through a MeshEditOp.  The extra functions are:

    test     return a code for the edit action that needs to be
             performed.  Actions given below.

    build    perform the mesh edit operation to reflect the current
             tool settings.

    end      clear the state when the last edit action is completed.
             This can be a result of the 'test' update code or it can
             be triggered by an external action.                       }
  PLWMeshEditTool = ^TLWMeshEditTool ;
  TLWMeshEditTool = record
    Instance : PLWInstance  ;
    Tool     : PLWToolFuncs ;

    Test     : function
               (       Instance : PLWInstance  ) : Integer  ;
    Build    : function
               (       Instance : PLWInstance  ;
                       MeshOp   : PMeshEditOp  ) : PLWError ;
    End_     : procedure
               (       Instance : PLWInstance  ;
                       Keep     : Integer      ) ;
  end;

  { The user memory normally passed to the MeshEdit->begin() is set with
    the return from the test() function. OR these values with the flag
    bits above to get per-vertex and per-polygon data allocated and accessed
    through userData pointers in the EDPointInfo and EDPolygonInfo structures. }
   function TLWT_VMEM( Size : Integer ) : Integer ;
   function TLWT_PMEM( Size : Integer ) : Integer ;

implementation

function TLWT_VMEM(Size: Integer): Integer;
begin
  Result := ((((Size + 7) shr 3) shl 24) and $FF000000);
end;

function TLWT_PMEM(Size: Integer): Integer;
begin
  Result := ((((Size + 7) shr 3) shl 16) and $00FF0000);
end;

end.

